﻿import QtQuick 2.15
import QtQuick.Controls 2.15

Item {
    id: itemAddPerson
    anchors.fill: parent
    visible: false

    MouseArea{
        anchors.fill: parent

        onPressed: {
            itemAddPerson.visible = false
        }
    }

    Rectangle{
        id: rectAddPerson
        width: parent.width*0.6
        height: parent.height*0.4
        color: "#404142"
        anchors.verticalCenter: parent.verticalCenter
        anchors.horizontalCenter: parent.horizontalCenter

        MouseArea{
            anchors.fill: parent
        }

        Button {
            id: leftAddPersonButton
            width: parent.height*0.2
            height: width/2
            anchors.left: parent.left
            anchors.bottom: parent.bottom
            anchors.leftMargin: width
            anchors.bottomMargin: height
            text: "确定"
            Connections{
                target: socketManager
                ignoreUnknownSignals:true
                function onFlushPage() {
                    console.log("onFlushPage is running...")
                    //刷新页面
                    pageStackView.clear(StackView.Immediate)
                    pageStackView.push("FirstPage.qml", StackView.Immediate)
                }
            }

            onClicked: {
                var dbData = dbManager.queryUserInfo("UserInfo")
                if(dbData){
                    var name = dbData[0].name
                    var number = dbData[0].number
                    var ip = dbData[0].ip
                    var port = dbData[0].port
                    var sendMap = {}
                    var img = dbData[0].img
                    sendMap = {"name": name, "number": number, "img": img, "ip": ip, "port": port}

                    socketManager.addOtherClient(textInputIP.text, Number(textInputPort.text), sendMap)
                }

            }
        }
        Button {
            id: rightAddPersonButton
            width: parent.height*0.2
            height: width/2
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            anchors.rightMargin: width
            anchors.bottomMargin: height
            text: "取消"

            onClicked: {
                itemAddPerson.visible = false
            }
        }

        Text {
            id: textAddPersonTip
            color: "#ffffff"
            text: qsTr("请输入你要添加的客户端IP和端口")
            anchors.top: parent.top
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
            font.bold: true
            font.pointSize: 10
            anchors.topMargin: parent.height*0.2
            anchors.horizontalCenter: parent.horizontalCenter
        }

        TextInput{
            id: textInputIP
            anchors.top: textAddPersonTip.bottom
            maximumLength: 15
            anchors.topMargin: parent.width*0.2
            width: parent.width*0.6
            height: width/10
            color: "#000000"
            anchors.left: parent.left
            anchors.leftMargin: height
            selectByMouse: true
            leftPadding: 2
            topPadding: 1
            z: 2
        }

        Rectangle{
            anchors.fill: textInputIP
            color: "#ffffff"
            z: 1
        }
        Text {
            color: "#ffffff"
            anchors.left: textInputIP.right
            anchors.top: textAddPersonTip.bottom
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
            font.bold: true
            anchors.topMargin: parent.width*0.2
            anchors.leftMargin: 5
            text: qsTr(":")
        }

        TextInput{
            id: textInputPort
            anchors.top: textAddPersonTip.bottom
            maximumLength: 5
            anchors.topMargin: parent.width*0.2
            width: parent.width*0.2
            height: textInputIP.height
            color: "#000000"
            anchors.left: textInputIP.right
            anchors.leftMargin: width/4
            selectByMouse: true
            leftPadding: 2
            topPadding: 1
            z: 2
        }

        Rectangle{
            anchors.fill: textInputPort
            color: "#ffffff"
            z: 1
        }
    }

}

/*##^##
Designer {
    D{i:0;autoSize:true;height:480;width:640}
}
##^##*/
